//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.baidu.trace;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import com.baidu.trace.api.fence.CircleFence;
import com.baidu.trace.api.fence.Fence;
import com.baidu.trace.api.fence.MonitoredAction;
import com.baidu.trace.api.fence.MonitoredStatus;
import com.baidu.trace.api.fence.MonitoredStatusInfo;
import com.baidu.trace.c.e;
import com.baidu.trace.model.CoordType;
import com.baidu.trace.model.LatLng;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONException;
import org.json.JSONObject;

public final class aj {
    private Map<Long, Fence> a = new ConcurrentHashMap();
    private Map<Long, MonitoredStatus> b = new ConcurrentHashMap();
    private bi c;

    protected final synchronized void a(String var1, LatLng var2, List<MonitoredStatusInfo> var3) {
        Iterator var4 = this.a.values().iterator();

        while(var4.hasNext()) {
            a.a((Fence)var4.next(), var1, var2, var3);
        }

    }

    protected final synchronized void a(bi var1, Handler var2) {
        Iterator var3 = this.a.values().iterator();

        while(true) {
            MonitoredStatus var6;
            CircleFence var10;
            do {
                while(true) {
                    do {
                        do {
                            Fence var4;
                            do {
                                if(!var3.hasNext()) {
                                    this.c = var1;
                                    return;
                                }
                            } while(!((var4 = (Fence)var3.next()) instanceof CircleFence));

                            var10 = (CircleFence)var4;
                        } while(!z.c.equals(var10.getMonitoredPerson()));
                    } while(var10.getDenoise() > 0 && var1.getRadius() > (double)var10.getDenoise());

                    LatLng var5 = var10.getCenter();
                    var6 = MonitoredStatus.unknown;
                    if(this.b.containsKey(Long.valueOf(var10.getFenceId()))) {
                        var6 = (MonitoredStatus)this.b.get(Long.valueOf(var10.getFenceId()));
                    }

                    double var8 = e.a(var5, var1.getLocation());
                    if(var10.getRadius() > var8) {
                        break;
                    }

                    if(MonitoredStatus.in == var6) {
                        this.b(var10.getFenceId(), MonitoredStatus.out);
                        this.a(var10, var1, MonitoredAction.exit, var2);
                    } else if(MonitoredStatus.unknown == var6) {
                        this.b(var10.getFenceId(), MonitoredStatus.out);
                    }
                }
            } while(MonitoredStatus.unknown != var6 && MonitoredStatus.out != var6);

            this.b(var10.getFenceId(), MonitoredStatus.in);
            if(MonitoredStatus.out == var6) {
                this.a(var10, var1, MonitoredAction.enter, var2);
            }
        }
    }

    private void a(CircleFence var1, bi var2, MonitoredAction var3, Handler var4) {
        JSONObject var5 = new JSONObject();
        JSONObject var6 = new JSONObject();
        JSONObject var7 = new JSONObject();

        try {
            var5.put("fence_id", var1.getFenceId());
            var5.put("fence", var1.getFenceName());
            var5.put("monitored_person", var1.getMonitoredPerson());
            var5.put("action", var3.name());
            var6.put("time", e.b());
            var6.put("latitude", var2.getLocation().latitude);
            var6.put("longitude", var2.getLocation().longitude);
            var6.put("radius", var2.getRadius());
            var6.put("coord_type", CoordType.bd09ll.name());
            var5.put("cur_point", var6);
            if(this.c == null) {
                this.c = var2;
            }

            var7.put("time", this.c.getLocTime());
            var7.put("latitude", this.c.getLocation().latitude);
            var7.put("longitude", this.c.getLocation().longitude);
            var7.put("radius", this.c.getRadius());
            var7.put("coord_type", CoordType.bd09ll.name());
            var5.put("pre_point", var7);
        } catch (JSONException var8) {
            return;
        }

        am.a(var1, var3, var6.toString(), var7.toString());
        Message var9;
        (var9 = var4.obtainMessage(163)).obj = var5.toString();
        var4.sendMessage(var9);
    }

    private void b(long var1, MonitoredStatus var3) {
        this.b.put(Long.valueOf(var1), var3);
        am.a(var1, var3);
    }

    protected final synchronized void a(long var1, Fence var3) {
        this.a.put(Long.valueOf(var1), var3);
    }

    protected final synchronized void a(long var1) {
        this.a.remove(Long.valueOf(var1));
    }

    protected final synchronized void a(long var1, MonitoredStatus var3) {
        this.b.put(Long.valueOf(var1), var3);
    }

    protected final synchronized boolean a() {
        return this.a == null || this.a.isEmpty();
    }

    protected final synchronized Fence b(long var1) {
        return this.a == null?null:(Fence)this.a.get(Long.valueOf(var1));
    }

    public aj(Context var1) {
        var1 = var1;

        try {
            File var3;
            if((var3 = new File("/data/data/" + e.c(var1) + "/shared_prefs", "fenceStatus.xml")).exists()) {
                var3.delete();
            }

        } catch (Exception var2) {
            ;
        }
    }

    protected final synchronized void b() {
        this.c();
        this.a = null;
        this.b = null;
    }

    protected final synchronized void c() {
        if(this.a != null) {
            this.a.clear();
        }

        if(this.b != null) {
            this.b.clear();
        }

    }
}
